package org.cfk.delaytasktutorial.example;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.cfk.delaytasktutorial.annotation.LazyJob;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class NotificationTask {

    public static final String WORKER_NAME = "notification_task";

    @Data
    public static class NotificationParam {
        private String userId;
        private String message;
        private String channel; // email, sms, push等
    }

    @LazyJob(WORKER_NAME)
    public void sendNotification(NotificationParam param) {
        log.info("开始发送延迟通知，用户：{}，渠道：{}，消息：{}",
                param.getUserId(), param.getChannel(), param.getMessage());
        
        // 这里模拟发送通知的具体实现
        try {
            Thread.sleep(100); // 模拟网络延迟
            log.info("通知发送成功：{}", param.getUserId());
        } catch (InterruptedException e) {
            log.error("通知发送失败：{}", param.getUserId(), e);
            Thread.currentThread().interrupt();
            throw new RuntimeException("发送通知失败", e);
        }
    }
}